// 账户信息
const accounts = [
    {
        user: 'fenglinz',
        password: '@Llen4012',
        projectId: '0f1ce8e14500f40e2f8dc00b9db4296a',
        identityUrl: 'iam.myhuaweicloud.com',
        describle: '四方云',
        regions: [{
            name: '华东-上海二',
            url: 'ecs.cn-east-2.myhuaweicloud.com',
            servers: [
                {
                    id: '65c2c51e-2155-427a-9b78-ae8eacb00054',
                    name: '应用服务器',
                    innerIP: '192.168.0.149',
                    outerIP: '121.36.134.210'
                }
            ]
        }]
    }
];

const metrics = [{
    name: 'cpu_util',
    text: 'CPU使用率',
    unit: '%',
    describle: '该指标用于统计测量对象的CPU使用率，以百分为单位。'
},
{
    name: 'mem_util',
    text: '内存使用率',
    unit: '%',
    describle: '该指标用于统计测量对象的内存使用率，以百分为单位。'
},
{
    name: 'disk_util_inband',
    text: '磁盘使用率',
    unit: '%',
    describle: '该指标用于统计测量对象的磁盘使用情况，以百分比为单位。'
},
{
    name: 'disk_read_bytes_rate',
    text: '磁盘读速率',
    unit: '字节/秒',
    describle: '该指标用于统计每秒从测量对象读出数据量，以字节/秒为单位。'
},
{
    name: 'disk_write_bytes_rate',
    text: '磁盘写速率',
    unit: '字节/秒',
    describle: '该指标用于统计每秒写到测量对象的数据量，以字节/秒为单位。'
},
{
    name: 'disk_read_requests_rate',
    text: '磁盘读操作速率',
    unit: '请求/秒',
    describle: '该指标用于统计每秒从测量对象读取数据的请求次数，以请求/秒为单位'
},
{
    name: 'network_incoming_bytes_rate_inband',
    text: '带内网络流入速率',
    unit: '字节/秒',
    describle: '该指标用于在测量对象内统计每秒流入测量对象的网络流量，以字节/秒为单位'
},
{
    name: 'network_outgoing_bytes_rate_inband',
    text: '带内网络流出速率',
    unit: '字节/秒',
    describle: '该指标用于在测量对象内统计每秒流出测量对象的网络流量，以字节/秒为单位。'
},
{
    name: 'network_incoming_bytes_aggregate_rate',
    text: '带外网络流入速率',
    unit: '字节/秒',
    describle: '该指标用于在虚拟化层统计每秒流入测量对象的网络流量，以字节/秒为单位。'
},
{
    name: 'network_outgoing_bytes_aggregate_rate',
    text: '带外网络流出速率',
    unit: '字节/秒',
    describle: '该指标用于在虚拟化层统计每秒流出测量对象的网络流量，以字节/秒为单位。'
},
{
    name: 'inst_sys_status_error',
    text: '系统状态检查失败',
    unit: '(0:正常;1:失败)',
    describle: '该指标用于监控运行弹性云服务器所需的云平台系统，以确保这些系统正常工作。'
}
];

const servers = [];

module.exports = {
    accounts: accounts,
    metrics: metrics,
    getAllServers () {
        if (servers && servers.length > 0) {
            return servers;
        }

        for (let account of accounts) {
            account.regions.forEach(region => servers.push(...(region.servers.map(c => {
                c.regionUrl = region.url;
                c.regionName = region.name;
                c.describle = account.describle;
                c.projectId = account.projectId;
                c.identityUrl = account.identityUrl;

                return c;
            }))));
        }

        return servers;
    },
    getServerDetail (ecsId) {
        return this.getAllServers().find(c => c.id == ecsId);
    },
    getAuth (projectId) {
        let account = accounts.find(c => c.projectId == projectId);

        return {
            auth: {
                identity: {
                    methods: ['password'],
                    password: {
                        user: {
                            name: account.user,
                            password: account.password,
                            domain: {
                                name: account.user
                            }
                        }
                    }
                },
                scope: {
                    domain: {
                        name: account.user
                    }
                }
            }
        };
    }
};